import React from 'react';
import {Modal} from 'antd';
import {
  InfoCircleFilled,
  CheckCircleFilled,
  CloseCircleFilled,
  ExclamationCircleFilled,
  QuestionCircleFilled
} from '@ant-design/icons';
import {childConfig as config} from '@/config';
import classnames from 'classnames';

Modal.config({
  rootPrefixCls: `${config.prefixCls}`,
});


// Modal 静态方法的默认配置
const modalMethodOption = option => ({
  ...option,
  prefixCls: `${config.prefixCls}-modal`,
  okButtonProps: {
    ...option.okButtonProps,
    className: classnames(
      `${config.prefixCls}-btn ${config.prefixCls}-btn-primary`,
      option.okButtonProps && option.okButtonProps.className,
    ),
  },
  cancelButtonProps: {
    ...option.cancelButtonProps,
    className: classnames(
      `${config.prefixCls}-btn`,
      option.cancelButtonProps && option.cancelButtonProps.className,
    ),
  },
});

class CustomizedModal {
  // 重写 Modal.info 方法
  info = props =>
    Modal.info.call(
      Modal,
      modalMethodOption({
        icon: <InfoCircleFilled/>,
        ...props,
      }),
    );

  // 重写 Modal.success 方法
  success = props =>
    Modal.success.call(
      Modal,
      modalMethodOption({
        icon: <CheckCircleFilled/>,
        ...props,
      }),
    );

// 重写 Modal.error 方法
  error = props =>
    Modal.error.call(
      Modal,
      modalMethodOption({
        icon: <CloseCircleFilled/>,
        ...props,
      }),
    );

// 重写 Modal.warning 方法
  warning = props =>
    Modal.warning.call(
      Modal,
      modalMethodOption({
        icon: <ExclamationCircleFilled/>,
        ...props,
      }),
    );

  // 重写 Modal.confirm 方法
  confirm = (props) => {
    console.log(1);
    Modal.confirm.call(
      Modal,
      modalMethodOption({
        icon: <QuestionCircleFilled/>,
        ...props,
      }),
    );
  }

}
// 新版本Modal不再是一个类，无法继承，只能改写重新覆盖Modal方法

Object.entries(Modal).forEach(([key, method]) => {
  if (CustomizedModal[key]) {
    Modal[key] = CustomizedModal[key];
  }
})

export default Modal;
